class Photo < ActiveRecord::Base
  validates_presence_of :title, :image_url, :thumbnail_url
  validates_uniqueness_of :title
  validates_format_of :image_url,
                      :with => %r{\.(jpg)$}i,
                      :message => "must be a URL for a JPG image"
  validates_format_of :thumbnail_url,
                      :with => %r{\.(jpg)$}i,
                      :message => "must be a URL for a JPG image"
  belongs_to :post

  
  def before_destroy
    # get rid of the image and thumbnails
    File.delete(RAILS_ROOT + "/public/" + self.thumbnail_url)
    File.delete(RAILS_ROOT + "/public/" + self.image_url)
  end
  
end
